package com.arice.dao;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.arice.SQLite.SQHelper;
import com.arice.beans.DataAnalystInfo;

public class DataAnalystDao {
	
	private SQHelper sqHelper;
	private SQLiteDatabase db;
	
	public DataAnalystDao(Context context){
		sqHelper = new SQHelper(context);
	}
	
	public List<DataAnalystInfo> getAllMoneyByuserId(int userId){
		db = sqHelper.getReadableDatabase();
		Cursor c = db.rawQuery("select 1,userId,codeId,incomeMoney,incomeTime,timeToInt from income where userId="+userId+
				" UNION  select 2, userid,codeid,expenseMoney,expenseTime,timeToInt from expense where userId="+userId+" ORDER BY timeToInt DESC", null);
		List<DataAnalystInfo> list = new ArrayList<DataAnalystInfo>();
		while (c.moveToNext()) {
			int type = c.getInt(0);
			int user = userId;
			int codeId = c.getInt(2);
			double money = c.getDouble(3);
			String time = c.getString(4);
			int timeToInt = c.getInt(5);
			list.add(new DataAnalystInfo(type, user, codeId, money, time, timeToInt));
		}
		c.close();
		db.close();
		return list;
	}

}
